{include file="public/header" /}





<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.course_list}</h3>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>


    <form method="get" name="formSearch" id="formSearch">
        <div class="ds-search-form">
            <!--教程名称-->
            <dl>
                <dt>{$Think.lang.course_name}</dt>
                <dd><input type="text" name="title" id="store_name" class="txt" value="{$Request.get.title|default=''}">
                </dd>
            </dl>

            <!--品牌-->
            <dl>
                <dt>{$Think.lang.course_brand}</dt>
                <dd>
                    <div id="ajax_brand" class="dssc-brand-select w180">
                        <div class="selection">
                            <input name="b_name" id="b_name" value="{$Request.param.b_name|default=''}" type="text"
                                class="txt w180" readonly="readonly" />
                            <input type="hidden" name="b_id" id="b_id" value="{$Request.param.b_id|default=''}" />
                        </div>
                        <div class="dssc-brand-select-container">
                            <div class="brand-index" data-url="{:url('Common/ajax_get_brand')}">
                                <div class="letter" dstype="letter">
                                    <ul>
                                        <li><a href="javascript:void(0);" data-letter="all">所有品牌</a></li>
                                        <li><a href="javascript:void(0);" data-letter="A">A</a></li>
                                        <li><a href="javascript:void(0);" data-letter="B">B</a></li>
                                        <li><a href="javascript:void(0);" data-letter="C">C</a></li>
                                        <li><a href="javascript:void(0);" data-letter="D">D</a></li>
                                        <li><a href="javascript:void(0);" data-letter="E">E</a></li>
                                        <li><a href="javascript:void(0);" data-letter="F">F</a></li>
                                        <li><a href="javascript:void(0);" data-letter="G">G</a></li>
                                        <li><a href="javascript:void(0);" data-letter="H">H</a></li>
                                        <li><a href="javascript:void(0);" data-letter="I">I</a></li>
                                        <li><a href="javascript:void(0);" data-letter="J">J</a></li>
                                        <li><a href="javascript:void(0);" data-letter="K">K</a></li>
                                        <li><a href="javascript:void(0);" data-letter="L">L</a></li>
                                        <li><a href="javascript:void(0);" data-letter="M">M</a></li>
                                        <li><a href="javascript:void(0);" data-letter="N">N</a></li>
                                        <li><a href="javascript:void(0);" data-letter="O">O</a></li>
                                        <li><a href="javascript:void(0);" data-letter="P">P</a></li>
                                        <li><a href="javascript:void(0);" data-letter="Q">Q</a></li>
                                        <li><a href="javascript:void(0);" data-letter="R">R</a></li>
                                        <li><a href="javascript:void(0);" data-letter="S">S</a></li>
                                        <li><a href="javascript:void(0);" data-letter="T">T</a></li>
                                        <li><a href="javascript:void(0);" data-letter="U">U</a></li>
                                        <li><a href="javascript:void(0);" data-letter="V">V</a></li>
                                        <li><a href="javascript:void(0);" data-letter="W">W</a></li>
                                        <li><a href="javascript:void(0);" data-letter="X">X</a></li>
                                        <li><a href="javascript:void(0);" data-letter="Y">Y</a></li>
                                        <li><a href="javascript:void(0);" data-letter="Z">Z</a></li>
                                        <li><a href="javascript:void(0);" data-letter="0-9">其他</a></li>
                                    </ul>
                                </div>
                                <div class="search" dstype="search"><input name="search_brand_keyword"
                                        id="search_brand_keyword" type="text" class="text" /><a
                                        href="javascript:void(0);" class="dssc-btn-mini"
                                        style="vertical-align: top;">Go</a></div>
                            </div>
                            <div class="brand-list" dstype="brandList">
                                <ul dstype="brand_list">
                                    {notempty name="brand_list"}
                                    {foreach name="brand_list" item="val"}
                                    <li data-id='{$val.brand_id}' data-name='{$val.brand_name}'>
                                        <em>{$val.brand_initial}</em>{$val.brand_name}</li>
                                    {/foreach}
                                    {/notempty}
                                </ul>
                            </div>
                            <div class="no-result" dstype="noBrandList" style="display: none;">
                                {$Think.lang.no_brand_result}</div>
                        </div>
                    </div>
                </dd>
            </dl>

            <!--教程状态-->
            <dl>
                <dt><label>{$Think.lang.course_status}</label></dt>
                <dd>
                    <select name="status">
                        <option value="">{$Think.lang.ds_please_choose}...</option>
                        <option value="1" {if isset($_GET['status']) && $_GET['status']==1 }selected{/if}>停用</option>
                        <option value="2" {if isset($_GET['status']) && $_GET['status']==2 }selected{/if}>启用</option>
                    </select>
                </dd>
            </dl>

            <!--教程类型-->
            <dl>
                <dt><label>教程类型：</label></dt>
                <dd>
                    <select name="type">
                        <option value="">{$Think.lang.ds_please_choose}...</option>
                        <option value="1" {if isset($_GET['type']) && $_GET['type']==1 }selected{/if}>综合</option>
                        <option value="2" {if isset($_GET['type']) && $_GET['type']==2 }selected{/if}>教程</option>
                        <option value="3" {if isset($_GET['type']) && $_GET['type']==3 }selected{/if}>技术资料</option>
                    </select>
                </dd>
            </dl>

            <!--教程分类-->
            <dl>
                <dt><label>教程分类：</label></dt>
                <dd id="searchgc_td"></dd>
                <input type="hidden" id="choose_gcid" name="choose_gcid" value="0"/>
                <select name="search_gc_id1" id="search_gc_id1">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                    {notemtpy name="$class_list"}
                    {foreach $class_list as $key => $val}
                    <option value="{$val.gc_id}" {$Request.param.search_gc_id1 == $val.gc_id ? 'selected' : ''}>{$val.gc_name}</option>
                    {/foreach}
                    {/notempty}
                </select>
                <select name="search_gc_id2" id="search_gc_id2">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
                <select name="search_gc_id3" id="search_gc_id3">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
            </dl>
            <!-- <dl>
                <dt>分类</dt>
                <select name="search_gc_id1" id="search_gc_id1">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                    {notemtpy name="$class_list"}
                    {foreach $class_list as $key => $val}
                    <option value="{$val.gc_id}" {$Request.param.search_gc_id1==$val.gc_id ? 'selected' : '' }>
                        {$val.gc_name}</option>
                    {/foreach}
                    {/notempty}
                </select>
                <select name="search_gc_id2" id="search_gc_id2">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
                <select name="search_gc_id3" id="search_gc_id3">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
            </dl> -->

            <div class="btn_group">
                <dd><input type="submit" class="btn" value="{$Think.lang.ds_search}"></dd>
                <a href="{:url('Course/index')}" class="btn btn-default"
                    title="{$Think.lang.ds_cancel}">{$Think.lang.ds_cancel}</a>
            </div>
        </div>
    </form>

    <table class="ds-default-table">
        <thead>
            <tr class="thead">
                <th>序号</th>
                <th>教程主图</th>
                <th>{$Think.lang.course_name}</th>
                <th>{$Think.lang.course_brand}</th>
                <th>{$Think.lang.course_category}</th>
                <th>教程类型</th>
                <th>{$Think.lang.course_status}</th>
                <th>热门</th>
                <th>收藏数</th>
                <th>{$Think.lang.course_set}</th>
            </tr>
        </thead>
        <tbody>
            {notempty name="course_list"}
            <?php $index=1; foreach($course_list as $k=>$v ){ ?>
            <tr class="hover edit" id="ds_row_{$v.id}">
                <td style="width: 50px;">
                    <span>{$index}</span>

                </td>
                <td style="width: 240px;">
                    <img src="{:course_thumb($v, 240)}" onload="javascript:ResizeImage(this,56,56);" />
                    <!--  <a class="btn-add-nofloat marginleft" href="{:url('Course/course_son_add',['course_id'=>$v.id])}"><span>{$Think.lang.ds_add_sub_class}</span></a>-->
                </td>
                <td style="width: 300px;">{$v.title}</td>
                <td style="width: 150px;">{$v.brand_name}</td>
                <td>{$v.gc_name}</td>
                <td><?php if($v['type']=='1'){echo '综合';}else if($v['type']=='2'){ echo '教程';}else{  echo '技术资料'; } ?>
                </td>
                <td>{$v.status}</td>
                <td><?php if($v['popular']=='0'){echo '否';}else if($v['popular']=='1'){ echo '是';} ?></td>
                <td>{$v.collection}</td>
                <td>
                    <a href="{:url('Course/course_son_list',['course_id'=>$v.id])}" class="dsui-btn-view">管理子教程</a>
                    <a href="{:url('Course/course_edit',['course_id'=>$v.id])}"
                        class="dsui-btn-edit">{$Think.lang.ds_edit}</a>
                    <a href="javascript:dsLayerConfirm('{:url('Course/goods_class_del',['course_id'=>$v.id])}','{$Think.lang.ds_ensure_del}',{$v.id})"
                        class="dsui-btn-del">{$Think.lang.ds_del}</a>
                </td>
            </tr>
            <?php $index++; }?>
            {else /}
            <tr class="no_data">
                <td colspan="10">{$Think.lang.ds_no_record}</td>
            </tr>
            {/notempty}
        </tbody>
    </table>
</div>

<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script src="{$Think.ADMIN_SITE_ROOT}/js/jquery.goods_class.js"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript">
    $(function () {
        //商品分类
        init_gcselect({
            $gc_choose_json
        }, {
            $gc_json
        });
        /* AJAX选择品牌 */
        $("#ajax_brand").brandinit();

        $('#dssubmit').click(function () {
            $('#formSearch').submit();
        });

        // 审核批量处理
        $('a[dstype="verify_batch"]').click(function () {
            ids_str = getItems();
            if (ids_str) {
                goods_verify(ids_str);
            }
        });
        // 违规下架批量处理
        $('a[dstype="lockup_batch"]').click(function () {
            ids_str = getItems();
            if (ids_str) {
                goods_lockup(ids_str);
            }
        });

        // ajax获取商品列表
        $('i[dstype="ajaxGoodsList"]').click(
            function () {

                var status = $(this).attr("status");
                if (status == 'open') {
                    $(this).attr('status', 'close');
                    $(this).removeClass('icon-jia').addClass('icon-jian');
                    var _parenttr = $(this).parents('tr');
                    var _commonid = $(this).attr('data-comminid');
                    var _div = _parenttr.next().find('.dssc-goods-sku');
                    if (_div.html() == '') {
                        $.getJSON('{:url("Goods/get_goods_list_ajax")}', {
                            commonid: _commonid
                        }, function (date) {
                            if (date != 'false') {
                                var _ul = $('<ul class="dssc-goods-sku-list"></ul>');
                                var res = eval('(' + date + ')');
                                for (var i = 0; i < res.length; i++) {
                                    $('<li><div class="goods-thumb" title="{$Think.lang.goods_serial}：' +
                                        res[i].goods_serial + '"><a href="' + res[i].url +
                                        '" target="_blank"><image src="' + res[i].goods_image +
                                        '" ></a></div>' + res[i].goods_spec +
                                        '<div class="goods-price">{$Think.lang.goods_price}：<em title="￥' +
                                        res[i].goods_price + '">￥' + res[i].goods_price +
                                        '</em></div><div class="goods-storage">{$Think.lang.goods_storage}：<em title="' +
                                        res[i].goods_storage + '">' + res[i].goods_storage +
                                        '</em></div><a href="' + res[i].url +
                                        '" target="_blank" class="dssc-btn-mini">{$Think.lang.show_goods_detail}</a></li>'
                                        ).appendTo(_ul);
                                    _ul.appendTo(_div);
                                    _parenttr.next().show();
                                }

                                // 计算div的宽度
                                _div.css('width', document.body.clientWidth - 54);

                                //                        _div.perfectScrollbar();
                            }
                        });
                    } else {
                        _parenttr.next().show()
                    }
                } else {
                    $(this).attr('status', 'open');
                    $(this).removeClass('icon-jian').addClass('icon-jia');
                    $(this).parents('tr').next().hide();
                }

            }
        );
    });

    // 获得选中ID
    function getItems() {
        /* 获取选中的项 */
        var items = '';
        $('.checkitem:checked').each(function () {
            items += this.value + ',';
        });
        if (items != '') {
            items = items.substr(0, (items.length - 1));
        } else {
            layer.alert('{$Think.lang.please_select_input}', {
                icon: 2
            })
        }
        return items;
    }
    //商品分类
    // init_gcselect({$gc_choose_json},{$gc_json});
    // function getGcId1(gc_id1, select_id) {
    //     var select_od = select_id;
    //     $.ajax({
    //         type: "GET",
    //         contentType: "application/json;charset=UTF-8",
    //         url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
    //         success: function (result) {
    //             result = JSON.parse(result);
    //             var html = '<option value="">选择分类</option>';
    //             for (var i = 0; i < result.length; i++) {
    //                 if (result[i].gc_id == select_id) {
    //                     html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
    //                         '</option>'
    //                 } else {
    //                     html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
    //                 }
    //             }
    //             $('#search_gc_id2').html(html)
    //         },
    //         //请求失败，包含具体的错误信息
    //         error: function (e) {
    //             console.log(e.status);
    //             console.log(e.responseText);
    //         }
    //     });
    // }

    // function getGcId2(gc_id1, select_id) {
    //     $.ajax({
    //         type: "GET",
    //         contentType: "application/json;charset=UTF-8",
    //         url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
    //         success: function (result) {
    //             result = JSON.parse(result);
    //             var html = '<option value="">选择分类</option>';
    //             for (var i = 0; i < result.length; i++) {
    //                 if (result[i].gc_id == select_id) {
    //                     html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
    //                         '</option>'
    //                 } else {
    //                     html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
    //                 }
    //             }
    //             $('#search_gc_id3').html(html)
    //         },
    //         //请求失败，包含具体的错误信息
    //         error: function (e) {
    //             console.log(e.status);
    //             console.log(e.responseText);
    //         }
    //     });
    // }
    function getGcId1(gc_id1, select_id) {
        var select_od = select_id;
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=UTF-8",
            url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
            success: function (result) {
                result = JSON.parse(result);
                var html = '<option value="">选择分类</option>';
                for (var i = 0; i < result.length; i++) {
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
                            '</option>'
                    } else {
                        html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
                    }
                }
                $('#search_gc_id2').html(html)
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }

    function getGcId2(gc_id1, select_id) {
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=UTF-8",
            url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
            success: function (result) {
                result = JSON.parse(result);
                var html = '<option value="">选择分类</option>';
                for (var i = 0; i < result.length; i++) {
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
                            '</option>'
                    } else {
                        html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
                    }
                }
                $('#search_gc_id3').html(html)
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
    // //获取下级分类
    // $('#search_gc_id1').on('change',function () {
    //     var gc_id1 = $(this).val();
    //     getGcId1(gc_id1)
    // })

    // $('#search_gc_id2').on('change',function () {
    //     var gc_id2 = $(this).val();
    //     getGcId2(gc_id2)
    // })
    //获取下级分类
    $('#search_gc_id1').on('change', function () {
        var gc_id1 = $(this).val();
        getGcId1(gc_id1)
    })

    $('#search_gc_id2').on('change', function () {
        var gc_id2 = $(this).val();
        getGcId2(gc_id2)
    })
    /* AJAX选择品牌 */
    $("#ajax_brand").brandinit();

    $('#dssubmit').click(function () {
        $('#formSearch').submit();
    });

    function submit_delete(ids_str) {
        _uri = ADMINSITEURL + "/Course/goods_class_del.html?gc_id=" + ids_str;
        dsLayerConfirm(_uri, '{$Think.lang.ds_ensure_del}');
    }
</script>
{if $Request.param.search_gc_id1}
<script>
    // 编辑初始化，处理分类选中的问题
    var gc_id1 = '{$Request.param.search_gc_id1}';
    var gc_id2 = '{$Request.param.search_gc_id2}';
    var gc_id3 = '{$Request.param.search_gc_id3}';
    getGcId1(gc_id1, gc_id2)
    getGcId2(gc_id2, gc_id3)
</script>
{/if}